<template>
	<view class="container">
		<view class="nav">
			<view class="item" :class="{'nav-active':navIndex==1}" data-id="1" @click="chooseNav">企业工厂-网络公司</view>
			<view class="item" :class="{'nav-active':navIndex==2}" data-id="2" @click="chooseNav">自定义话题</view>
		</view>

		<view class="huati" v-if="navIndex ==1">
			<block v-for="item,index in systemTalkList" :key="item.id">
				<view class="item">
					<view style="display: flex;align-items: center;">
						<view class="biaoqian">#</view>
						<view class="title">{{item.seoTitle}}</view>
					</view>
					<!-- <image src="../../static/images/delete.png" style="height: 46rpx;width: 46rpx;" mode=""></image> -->
				</view>
			</block>


		</view>

		<view class="huati" v-if="navIndex ==2" style="padding: 120rpx 0;">
			<view class="zidingyi-btn" @click="openZidingyi">
				+添加自定义话题
			</view>
			<block v-for="item,index in userTalkList" :key="item.id">
				<view class="item">
					<view style="display: flex;align-items: center;">
						<view class="biaoqian">#</view>
						<view class="title">{{item.seoTitle}}</view>
					</view>
					<image src="../../static/images/delete.png" style="height: 46rpx;width: 46rpx;" :data-id="item.id"
						@click="del"></image>
				</view>
			</block>
		</view>
		<view class="footer">
			<view class="left">
				<view class="yuan">

				</view>
				<!-- <image src="../../static/images/choose.png" style="height: 30rpx;width: 30rpx;"></image> -->
				<text>只用自定义话题</text>
			</view>
			<view class="right">确定</view>
		</view>

		<!-- 自定义话题模态框 start -->
		<uni-popup ref="popup" background-color="rgba(0,0,0,0)" type="bottom">
			<view class="radius">
				<view class="header">
					<view>自定义话题</view>
					<view style="font-weight: normal;font-size: 48rpx;color: #666" @click="closeZidingyi">x</view>
				</view>
				<view class="header-tip">
					当前所选行业：企业工厂-网络公司；默认优先使用自定义。
				</view>
				<view class="huati-box">
					<view class="biaoqian">
						#
					</view>
					<input class="huati-input" v-model="huatiInput" placeholder="请输入话题SEO" />

				</view>
				<view class="tip">
					提示：话题内容最多16个字
				</view>
				<view class="huati-footer">
					<view class="cancel" @click="closeZidingyi">
						取消
					</view>
					<view class="submit" @click="submit">
						确定
					</view>
				</view>
			</view>

		</uni-popup>
		<!-- 字自定义话题模态框 start -->
	</view>
</template>

<script>
	import Http from "@/utils/http"
	const http = new Http()
	export default {
		data() {
			return {
				navIndex: 1,
				huatiInput: "",
				userTalkList: [],
				systemTalkList: []
			}
		},
		onLoad() {
			this.getSystemTalk()
			
		},
		methods: {
			getUserTalk() {
				http.get("v1/subjectTalk/userTalkList?jobId=1").then(res => {
					this.userTalkList = res.data.data
				})
			},
			getSystemTalk() {
				http.get("v1/subjectTalk/systemTalkList?jobId=1").then(res => {
					this.systemTalkList = res.data.data
				})
			},
			chooseNav(e) {

				let id = e.currentTarget.dataset.id
				this.navIndex = id
				if (this.navIndex == 1) {
					this.getSystemTalk()
				} else {
					this.getUserTalk()
				}

			},
			//开启视频字体颜色
			openZidingyi() {
				this.$refs.popup.open()
			}, //关闭视频字体颜色
			closeZidingyi() {
				this.$refs.popup.close()
			},
			//提交自定义话题
			submit() {
				console.log(this.huatiInput);
				http.post("v1/subjectTalk/add", {
					seoTitle: this.huatiInput,
					jobId: 1
				}).then(res => {
					if (res.data.code == 200) {
						this.huatiInput = ""
						this.$refs.popup.close()
						this.getUserTalk()
						return uni.showToast({
							title: "添加成功",
							icon: "none"
						})
					} else {
						return uni.showToast({
							title: "添加失败",
							icon: "none"
						})
					}
					console.log("====>", res);
				})
			},
			del(e) {
				http.post("v1/subjectTalk/del", {
					id: e.currentTarget.dataset.id
				}).then(res => {
					if (res.data.code == 200) {
						this.getUserTalk()
						return wx.showToast({
							title: "删除成功",
							icon: "none"
						})
					} else {
						return wx.showToast({
							title: "删除失败",
							icon: "none"
						})
					}
				})
			}

		}
	}
</script>

<style scoped lang="scss">
	page {
		background: #f1f1f1;
	}

	.nav {
		display: flex;
		font-size: 36rpx;
		margin: 0 30rpx 30rpx 30rpx;
		justify-content: space-between;
		align-items: center;
		position: fixed;
		z-index: 99;
		left: 0;
		right: 0;
		top: 0;
		background: #f1f1f1;

		.item {
			height: 90rpx;
			line-height: 90rpx;
			// color: #333;
			// border-bottom: 4rpx solid #f1f1f1;
			// 
		}
	}

	.huati {
		padding: 120rpx 0;

		.item {
			margin: 0 30rpx 30rpx 30rpx;
			background: #fff;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			padding: 26rpx 20rpx;
			justify-content: space-between;

			.biaoqian {
				height: 46rpx;
				width: 46rpx;
				line-height: 46rpx;
				text-align: center;
				background-color: #d4237a;
				color: #fff;
				border-radius: 23rpx;
				font-size: 34rpx;
				font-weight: bold;
			}

			.title {
				font-size: 32rpx;
				margin-left: 10rpx;
			}
		}
	}

	.footer {
		background: #fff;
		height: 110rpx;
		display: flex;
		align-items: center;
		position: fixed;
		justify-content: space-between;
		padding: 0 30rpx;
		z-index: 99;
		left: 0;
		bottom: 0;
		right: 0;

		.left {
			font-size: 32rpx;
			display: flex;
			align-items: center;

			.yuan {
				width: 30rpx;
				height: 30rpx;
				border: 2rpx solid #999;
				border-radius: 15rpx;
				margin-right: 10rpx;
			}
		}

		.right {
			width: 220rpx;
			font-size: 32rpx;
			color: #fff;
			background-color: #d4237a;
			height: 70rpx;
			line-height: 79rpx;
			border-radius: 40rpx;
			text-align: center;
		}
	}

	//自定义话题
	.zidingyi-btn {
		margin: 30rpx;
		border: 1rpx solid #d4237a;
		color: #d4237a;
		font-size: 30rpx;
		text-align: center;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 40rpx;
	}

	//自定义话题
	.radius {
		height: 450rpx;
		background: #fff;
		border-top-left-radius: 30rpx;
		border-top-right-radius: 30rpx;
		overflow: hidden;
		border: 1rpx solid #fff;
		position: relative;


		.header {
			font-size: 36rpx;
			font-weight: bold;
			height: 100rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #fff;
			margin: 0 30rpx;

		}

		.header-tip {
			font-size: 28rpx;
			padding: 20rpx 30rpx;
		}

		.huati-box {
			display: flex;
			padding: 10rpx 30rpx 20rpx 30rpx;
			align-items: center;

			.biaoqian {
				height: 46rpx;
				width: 46rpx;
				line-height: 46rpx;
				text-align: center;
				background-color: #d4237a;
				color: #fff;
				border-radius: 23rpx;
				font-size: 34rpx;
				font-weight: bold;
			}

			.huati-input {
				border: 1rpx solid #eee;
				background: #f1f1f1;
				font-size: 32rpx;
				color: #666;
				flex: 1;
				height: 70rpx;
				border-radius: 8rpx;
				margin-left: 20rpx;
				text-indent: 20rpx;
			}
		}

		.tip {
			font-size: 28rpx;
			color: red;
			margin-left: 30rpx;

		}

		.huati-footer {
			display: flex;
			margin: 30rpx 30rpx 20rpx 30rpx;
			align-items: center;
			justify-content: space-between;
			font-size: 32rpx;
			font-weight: bold;

			.cancel {
				width: 42%;
				height: 80rpx;
				background: #eee;
				line-height: 80rpx;
				border-radius: 40rpx;
				text-align: center;
			}

			.submit {
				width: 42%;
				height: 80rpx;
				background: orange;
				line-height: 80rpx;
				color: #fff;
				border-radius: 40rpx;
				text-align: center;
			}
		}
	}

	.nav-active {
		color: #d4237a;
		border-bottom: 6rpx solid #d4237a;
	}
</style>